//
//  JDGoodsDetailViewController.swift
//  DragonWallet
//
//  Created by volantPig on 2024/4/15.
//

import UIKit
import Kingfisher
import FSPagerView
import WebKit

class JDGoodsDetailViewController: JDBaseViewController {

    var goodsLogoUrl: String?
    /// 商品id 由上个页面传值过来
    var goodsID: String?
    var goodsDetailModel: JDGoodsDetailModel?
    var goodsSpecList: [JDGoodsSpecModel?]?
    var goodsSkuList: [JDGoodsSkuModel?]?
    
    var bottomToolBarView: UIView?
    var addShopCartButton: UIButton?
    var buyButton: UIButton?
    
    var mainTableView: UITableView?
    
    var bannerNumberLabel: JDPaddingLabel?
    var newBannerView:FSPagerView?
    var bannerView: JDBannerView?
    var goodsDescriptionView: JDGoodsDescriptionView?
    
    var cellHeightArray:[CGFloat] = [0.00,0.00]//[CGFloat]()
    
    var backButton: UIButton?
    
    var hintContainerView: UIView?
    var hintLabel: UILabel?
    var hintCloseButton: UIButton?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.setupConfig()
        self.setupUIElements()
        self.getNetData()
        // Do any additional setup after loading the view.
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
//        self.navigationController?.navigationBar.isHidden = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
//        self.navigationController?.navigationBar.isHidden = false
    }
    
    
    func setupConfig() {
//        self.setupLeftBackItem()
        self.navigationItem.hidesBackButton = true
//        self.navigationController?.navigationBar.isHidden = true
        
        self.backButton = UIButton(type: .custom)
        self.view.addSubview(self.backButton!)
        self.backButton?.snp.makeConstraints { make in
            make.left.equalTo(self.view)
            make.top.equalTo(self.view).offset(UIDevice().safeAreaInset.top-44)
            make.size.equalTo(CGSizeMake(44, 44))
        }
        self.backButton?.setImage(UIImage(named: "detail_back")?.withRenderingMode(.alwaysOriginal), for: .normal)
        self.backButton?.addTarget(self, action: #selector(backAction), for: .touchUpInside)
        
    }
    
    func setupUIElements() {
        self.bottomToolBarView = UIView()
        self.view.addSubview(self.bottomToolBarView!)
        self.bottomToolBarView?.snp.makeConstraints({ make in
            make.left.right.bottom.equalTo(self.view)
            make.height.equalTo(104)
        })
        self.bottomToolBarView?.backgroundColor = .white
        
        self.addShopCartButton = UIButton(type: .custom)
        self.bottomToolBarView?.addSubview(self.addShopCartButton!)
        self.addShopCartButton?.snp.makeConstraints({ make in
            make.left.equalTo(self.bottomToolBarView!).offset(12)
            make.centerY.equalTo(self.bottomToolBarView!).offset(-17)
            make.right.equalTo(self.bottomToolBarView!.snp.centerX).offset(-5)
            make.height.equalTo(48)
        })
        self.addShopCartButton?.layer.borderColor = color("#FA6161").cgColor
        self.addShopCartButton?.layer.borderWidth = 1
        self.addShopCartButton?.setTitleColor(color("#FA6161"), for: .normal)
        self.addShopCartButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        self.addShopCartButton?.setTitle("加入购物车", for: .normal)
        self.addShopCartButton?.layer.cornerRadius = 24
        self.addShopCartButton?.addTarget(self, action: #selector(addShopcartAction), for: .touchUpInside)
        
        self.buyButton = UIButton(type: .custom)
        self.bottomToolBarView?.addSubview(self.buyButton!)
        self.buyButton?.snp.makeConstraints({ make in
            make.left.equalTo(self.bottomToolBarView!.snp.centerX).offset(5)
            make.right.equalTo(self.bottomToolBarView!).offset(-12)
            make.centerY.equalTo(self.bottomToolBarView!).offset(-17)
            make.height.equalTo(48)
        })
        self.buyButton?.backgroundColor = color("#FA6161")
        self.buyButton?.setTitle("立即购买", for: .normal)
        self.buyButton?.setTitleColor(.white, for: .normal)
        self.buyButton?.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: .regular)
        self.buyButton?.layer.cornerRadius = 24
        self.buyButton?.addTarget(self, action: #selector(buyAtOnceAction), for: .touchUpInside)
        
        self.mainTableView = UITableView(frame: .zero, style: .grouped)
        self.view.addSubview(self.mainTableView!)
        self.mainTableView?.snp.makeConstraints({ make in
            make.left.equalTo(self.view)
            make.right.equalTo(self.view)
            make.top.equalTo(self.view).offset(-statusBarHeight)
            make.bottom.equalTo(self.bottomToolBarView!.snp.top)
        })
        self.mainTableView?.separatorStyle = .none
        self.mainTableView?.delegate = self
        self.mainTableView?.dataSource = self
        self.mainTableView?.register(UITableViewCell.self, forCellReuseIdentifier: "myCell")
        self.mainTableView?.register(JDSingleImageViewTableViewCell.self, forCellReuseIdentifier: "singleImageCell")
        self.mainTableView?.tableHeaderView = self.createTableViewHeaderView()
        
        self.view.bringSubviewToFront(self.backButton!)
        
        self.hintContainerView = UIView()
        self.view.addSubview(self.hintContainerView!)
        self.hintContainerView?.snp.makeConstraints({ make in
            make.left.equalTo(self.view).offset(12)
            make.right.equalTo(self.view).offset(-12)
            make.bottom.equalTo(self.bottomToolBarView!.snp.top).offset(-9)
            make.height.equalTo(35)
        })
        self.hintContainerView?.makeCorner(17.5)
        self.hintContainerView?.backgroundColor = color("#333333").withAlphaComponent(0.8)
        
        self.hintCloseButton = UIButton(type: .custom)
        self.hintContainerView?.addSubview(self.hintCloseButton!)
        self.hintCloseButton?.snp.makeConstraints({ make in
            make.right.equalTo(self.hintContainerView!).offset(-12)
            make.centerY.equalTo(self.hintContainerView!)
            make.size.equalTo(CGSizeMake(16, 16))
        })
//        self.hintCloseButton?.setTitle("X", for: .normal)
        self.hintCloseButton?.setImage(UIImage(named: "goodsDetail_close")?.withRenderingMode(.alwaysOriginal), for: .normal)
        self.hintCloseButton?.addTarget(self, action: #selector(closeHintView), for: .touchUpInside)
        
        
        self.hintLabel = UILabel()
        self.view.addSubview(self.hintLabel!)
        self.hintLabel?.snp.makeConstraints({ make in
            make.left.equalTo(self.hintContainerView!).offset(12)
            make.right.equalTo(self.hintCloseButton!.snp.left)
            make.top.bottom.equalTo(self.hintContainerView!)
        })
        hintLabel?.makeCorner(17.5)
        hintLabel?.labelConfig(textAlignment: .center, font: UIFont.systemFont(ofSize: 13), textColor: .white)
        hintLabel?.text = "购买跨境商品，平台接单后不接受取消订单或商品退换诉求。"
        hintLabel?.adjustsFontSizeToFitWidth = true
    }
    
    func getNetData() {
        
        var params = [String: Any]()
        params["goodsId"] = self.goodsID
        
        JDNetWorkRequest(.getGoodsDetail(params)) { responseStr in
            
            printLog("商品详情数据:\(responseStr)")
            let commonModel = JDCommonModel.deserialize(from: responseStr, designatedPath: "")
            if commonModel?.code == "0" {
                if let model = JDGoodsDetailModel.deserialize(from: responseStr, designatedPath: "data") {
                    self.goodsDetailModel = model
                    
//                    if let imgUrls = model.goodsBannerSlideImgUrl {
//                        self.bannerView?.updateImgNameArray(imgArray: imgUrls)
//                    }
                    
                }
            }
            self.mainTableView?.reloadData()
            self.bannerNumberLabel?.text = String(format: "%d/%d", 1,self.goodsDetailModel?.goodsBannerSlideImgUrl?.count ?? 0)
            self.newBannerView?.reloadData()
            
        } failure: { error in
            
        } error: { errorCode in
            
        }
        
//        var params = [String: Any]()
//        params["goodsid"] = self.goodsID
////        params["onlineSign"] = JDLoginModel.default.onlineSign
//
//        JDNetWorkRequest(.goodsDetail(params)) { responseStr in
//            let commonModel = JDCommonModel.deserialize(from: responseStr, designatedPath: "")
//            if commonModel?.code == "0" {
//                // 成功
//                self.goodsDetailModel = JDGoodsDetailModel.deserialize(from: responseStr, designatedPath: "data")
//
//                // MARK: 处理信息 goodsPicurlList
//                self.goodsDetailModel?.goods?.goodsPicurlList
//
//                var bannerPicList = [String]()
//                for picPath in self.goodsDetailModel?.goods?.goodsPicurlList ?? [String]() {
//                    let fullPath = String.init(format: "%@%@", JDImageBaseUrl,picPath)
//                    bannerPicList.append(fullPath)
//                }
//                self.bannerView?.updateImgNameArray(imgArray: bannerPicList)
//            }
//
////            self.bannerView?.updateImgNameArray(imgArray: ["https://copyright.bdstatic.com/vcg/creative/cc9c744cf9f7c864889c563cbdeddce6.jpg","https://copyright.bdstatic.com/vcg/creative/cc9c744cf9f7c864889c563cbdeddce6.jpg"])
//
//            printLog("商品详情信息:\(responseStr)")
//
//            self.mainTableView?.reloadData()
//
//
//        } failure: { error in
//            self.mainTableView?.reloadData()
//        } error: { errorCode in
//            self.mainTableView?.reloadData()
//        }

        // 获取规格信息
        var specificationParams = [String: Any]()
        specificationParams["id"] = self.goodsID
        JDNetWorkRequest(.getGoodsSpecification(specificationParams)) { responseStr in
            
            printLog("规格信息:\(responseStr)")
            let commonModel = JDCommonModel.deserialize(from: responseStr, designatedPath: "")
            if commonModel?.code == "0" {
                if let model = [JDGoodsSpecModel].deserialize(from: responseStr, designatedPath: "data") {
                    self.goodsSpecList = model
                }
            }
            
//            {"msg":"ok","data":[{"specificationImgUrl":"https:\/\/d1nhio0ox7pgb.cloudfront.net\/_img\/g_collection_png\/standard\/256x256\/leaf.png","salePrice":150000,"salePriceText":"150.00","goodsId":1,"specificationId":1,"specificationName":"黑色"},{"specificationImgUrl":"https:\/\/d1nhio0ox7pgb.cloudfront.net\/_img\/g_collection_png\/standard\/256x256\/leaf.png","salePrice":160000,"salePriceText":"160.00","goodsId":1,"specificationId":2,"specificationName":"白色"},{"specificationImgUrl":"https:\/\/d1nhio0ox7pgb.cloudfront.net\/_img\/g_collection_png\/standard\/256x256\/leaf.png","salePrice":250000,"salePriceText":"250.00","goodsId":1,"specificationId":3,"specificationName":"五彩斑斓黑"}],"code":0}
            
        } failure: { error in
            
        } error: { errorCode in
            
        }
        
        var skuParams = [String: Any]()
        skuParams["id"] = self.goodsID
        JDNetWorkRequest(.getGoodsSku(skuParams)) { responseStr in
            
            let commonModel = JDCommonModel.deserialize(from: responseStr, designatedPath: "")
            if commonModel?.code == "0" {
                print("sku信息:\(responseStr)")
                
                if let models = [JDGoodsSkuModel].deserialize(from: responseStr, designatedPath: "data") {
                    
                    self.goodsSkuList = models
                    
                }
            }
            
        } failure: { error in
            
        } error: { errorCode in
            
        }
        
    }
    
    func createTableViewHeaderView() -> UIView {
        
        let headerView = UIView()
        headerView.frame = CGRectMake(0, 0, screenWidth, screenWidth+10)
        
        self.newBannerView = FSPagerView.init(frame: CGRectMake(0, 100, screenWidth, screenWidth))
        self.newBannerView?.backgroundColor = .commonColor()
        headerView.addSubview(newBannerView!)
        self.newBannerView?.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
        self.newBannerView?.itemSize = FSPagerView.automaticSize
        self.newBannerView?.delegate = self
        self.newBannerView?.dataSource = self
        self.newBannerView?.automaticSlidingInterval = 3
        self.newBannerView?.snp.makeConstraints({ make in
            make.left.right.top.equalTo(headerView)
            make.height.equalTo(screenWidth)
        })
        
        self.bannerNumberLabel = JDPaddingLabel()
        headerView.addSubview(self.bannerNumberLabel!)
        self.bannerNumberLabel?.snp.makeConstraints({ make in
            make.trailing.equalTo(headerView)//.offset(-12)
            make.bottom.equalTo(headerView).offset(-10)
            make.height.equalTo(30)
        })
//        self.bannerNumberLabel?.makeCorner(19)
        self.bannerNumberLabel?.edgeInsets = UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 12)
        self.bannerNumberLabel?.labelConfig(textAlignment: .center, font: UIFont.systemFont(ofSize: 12, weight: .regular), textColor: color("#FFFFFF"), numberOfLines: 1)
        self.bannerNumberLabel?.text = "0/0"
        self.bannerNumberLabel?.backgroundColor = color("#333333").withAlphaComponent(0.8)
        
        return headerView
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */
    @objc func closeHintView() {
        self.hintContainerView?.isHidden = true
        self.hintLabel?.isHidden = true
        self.hintCloseButton?.isHidden = true
    }
    
    @objc func addShopcartAction() {
        if !JDTools.checkToken() {
            return;
        }
        printLog("加入购物车:\(self.goodsLogoUrl)")
        
        // 这个是规格数组
        let addShopcartView = JDAddShopcartView()
        addShopcartView.goodsLogoUrl = self.goodsLogoUrl
        addShopcartView.goodsDetailModel = self.goodsDetailModel
        addShopcartView.basePrice = self.goodsDetailModel?.salePriceText
        addShopcartView.addType = .shopcart
        addShopcartView.goodsSpecModels = self.goodsSpecList
        addShopcartView.goodsSkuList = self.goodsSkuList
        JDTools.getKeyWindows()?.rootViewController?.view.addSubview(addShopcartView)
    }
    
    @objc func buyAtOnceAction() {
        if !JDTools.checkToken() {
            return;
        }
        printLog("立即购买")
        let buyAtOnceView = JDAddShopcartView()
        buyAtOnceView.goodsLogoUrl = self.goodsLogoUrl
        buyAtOnceView.goodsDetailModel = self.goodsDetailModel
        buyAtOnceView.basePrice = self.goodsDetailModel?.salePriceText
        buyAtOnceView.addType = .buy
        buyAtOnceView.goodsSkuList = self.goodsSkuList
        buyAtOnceView.goodsSpecModels = self.goodsSpecList
        buyAtOnceView.baseVC = self
        JDTools.getKeyWindows()?.rootViewController?.view.addSubview(buyAtOnceView)
    }

}

extension JDGoodsDetailViewController: UITableViewDelegate, UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return 1
        } else if section == 1 {
            return 1
        } else if section == 2 {
            
            let imagesArray = self.goodsDetailModel?.goodsDetailImgUrl?.components(separatedBy: ",")
            
            return imagesArray?.count ?? 0
            
//            return self.goodsDetailModel?.goodsBannerSlideImgUrl?.count ?? 0
        } else {
            return 0
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        if indexPath.section == 2 {
            let singleImageCell = tableView.dequeueReusableCell(withIdentifier: "singleImageCell") as? JDSingleImageViewTableViewCell
            
            let imagesArray = self.goodsDetailModel?.goodsDetailImgUrl?.components(separatedBy: ",")
            print("先看这个个数:\(imagesArray)")
            let imageName = imagesArray?[indexPath.row] ?? "." //(self.goodsDetailModel?.goodsBannerSlideImgUrl?[indexPath.row] ?? ".")
            singleImageCell?.updateValueForCell(imageURL: imageName)
//            singleImageCell?.finishLoadImageBlock = { [weak self] _ in
//                self?.cellHeightArray[indexPath.row] = singleImageCell?.detailCellHeight ?? 0.00
//                tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.none)
//            }
            
            return singleImageCell!
        }
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "myCell")
        cell?.selectionStyle = .none
        
        for subV in cell?.contentView.subviews ?? [UIView]() {
            subV.removeFromSuperview()
        }
        
        if indexPath.section == 0 {
            
            if self.goodsDescriptionView == nil {
                self.goodsDescriptionView = JDGoodsDescriptionView()
            }
            self.goodsDescriptionView?.snp.removeConstraints()
            cell?.contentView.addSubview(self.goodsDescriptionView!)
            self.goodsDescriptionView?.snp.makeConstraints({ make in
                make.left.top.right.bottom.equalTo(cell!.contentView)
            })
            self.goodsDescriptionView?.refreshData(goodsModel: self.goodsDetailModel)
            
        }
        else if indexPath.section == 1 {
            // 描述
            cell?.backgroundColor = .clear
            cell?.contentView.backgroundColor = .clear//.commonColor()
            
            let containerView = UIView()
            cell?.contentView.addSubview(containerView)
            containerView.snp.makeConstraints { make in
                make.left.equalTo(cell!.contentView).offset(12)
                make.right.equalTo(cell!.contentView).offset(-12)
                make.top.equalTo(cell!.contentView)
                make.bottom.equalTo(cell!.contentView)
            }
            containerView.backgroundColor = .white
            containerView.makeCorner(8)
            
            let detailTitle = UILabel()
            containerView.addSubview(detailTitle)
            detailTitle.snp.makeConstraints { make in
                make.top.equalTo(containerView).offset(17)
                make.left.equalTo(containerView).offset(12)
            }
            detailTitle.text = "详情"
            detailTitle.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 16, weight: .semibold), textColor: color("#333333"))
//            
//            let wkWebView = WKWebView()
//            containerView.addSubview(wkWebView)
//            wkWebView.scrollView.isScrollEnabled = false
//            wkWebView.isOpaque = false
////            <html><body><h1>Hello, World!</h1></body></html>
//            let baseCode = """
//            <!DOCTYPE html>
//            <html>
//            <body>
//            %@
//            </body>
//            </html>
//            """
////            style="font-family:arial;color:red;font-size:20px;"
//            
//            let htmlContent = String(format: baseCode, self.goodsDetailModel?.detailHtml ?? "").replacingOccurrences(of: "<p>", with: "<p style=\"font-family:arial;font-size:48px;\">")
//            wkWebView.loadHTMLString(htmlContent, baseURL: nil)
//            wkWebView.sizeToFit()
//            wkWebView.snp.makeConstraints { make in
//                make.left.equalTo(containerView).offset(12)
//                make.right.equalTo(containerView).offset(-12)
//                make.top.equalTo(detailTitle.snp.bottom).offset(8)
//                make.bottom.equalTo(containerView).offset(-12)
//                make.height.equalTo(100)
//            }
//            
//            print("这个内容:\(self.goodsDetailModel?.detailHtml)")
//            
            let detailLabel = UILabel()
            containerView.addSubview(detailLabel)
            detailLabel.snp.makeConstraints { make in
                make.left.equalTo(containerView).offset(12)
                make.right.equalTo(containerView).offset(-12)
                make.top.equalTo(detailTitle.snp.bottom).offset(8)
                make.bottom.equalTo(containerView).offset(-12)
            }
            detailLabel.text = self.goodsDetailModel?.goodsSummary
            detailLabel.labelConfig(textAlignment: .left, font: UIFont.systemFont(ofSize: 16, weight: .regular), textColor: color("#333333"), numberOfLines: 0)
            
        }
        
        return cell!
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
//        tableView.deselectRow(at: indexPath, animated: false)
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0 {
            return UITableView.automaticDimension
        }
        if indexPath.section == 1 {
            return UITableView.automaticDimension
        }
        if indexPath.section == 2 {
            
//            if self.cellHeightArray.count > indexPath.row {
//                
//                let imagesArray = self.goodsDetailModel?.goodsDetailImgUrl?.components(separatedBy: ",")
//                let imageName = imagesArray?[indexPath.row] ?? "."
////                let imageName = String.init(format: "%@%@", JDImageBaseUrl,(self.goodsDetailModel?.goods?.goodsXqPicurlList?[indexPath.row] ?? "."))
//                if let image = KingfisherManager.shared.cache.retrieveImageInMemoryCache(forKey: imageName) {
//                    let scale = (screenWidth-24)/image.size.width
//                    let height = image.size.height*scale
//                    printLog("比例:\(scale),宽高:\(screenWidth)<->\(height)")
//                    return height
//                }
//                return self.cellHeightArray[indexPath.row]
//            }
            return screenWidth
            
        }
        return 0
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
//        if section == 1 {
//            return 0
//        }
        return 10
    }
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        return nil
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        if section == 1 {
            return nil
        }
        let footerView = UIView()
        footerView.backgroundColor = .clear
        return footerView
    }
}

extension JDGoodsDetailViewController: JDBannerViewDelegate {
    func bannerDidselected(banner: JDBannerView, index: Int) {
        
        let imgUrl = self.goodsDetailModel?.goodsBannerSlideImgUrl?[index]
        
        printLog("点击banner:\(imgUrl)")
        
//        if let model = self.bankGoodsModel?.dataObject {
//            if let speThumbnail = model.speThumbnail {
//                let bannerArray = speThumbnail.components(separatedBy: ";")
//                var urlArr = [URL]()
//                for imgUrl in bannerArray {
//                    urlArr.append((URL.init(string: imgUrl))!)
//                }
////                WJBTools.showWebImages(urlArray: bannerArray, idx: index)
//
//            }
//        }
    }
}


extension JDGoodsDetailViewController: FSPagerViewDataSource,FSPagerViewDelegate {
    public func numberOfItems(in pagerView: FSPagerView) -> Int {
        print("这里走了么:\(self.goodsDetailModel?.goodsBannerSlideImgUrl?.count)")
        return self.goodsDetailModel?.goodsBannerSlideImgUrl?.count ?? 0
//        return self.imageNames.count
    }
    
    public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
        let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index)
        
        let imageUrl = self.goodsDetailModel?.goodsBannerSlideImgUrl?[index] ?? ""
        
        print("图片信息啊:\(imageUrl)")
        if imageUrl.hasPrefix("http") {
            cell.imageView?.kf.setImage(with: URL(string: imageUrl), placeholder: UIImage.init(named: "x"), options: nil, completionHandler: { result in
            })
        } else {
            cell.imageView?.downloadImage(imageUrl)
        }
//        cell.imageView?.image = UIImage(named: self.imageNames[index])
        cell.imageView?.contentMode = .scaleAspectFill
        cell.imageView?.clipsToBounds = true
        
        cell.textLabel?.isHidden = true
        cell.textLabel?.superview?.isHidden = true
        return cell
    }
    
    // MARK:- FSPagerView Delegate
    func pagerView(_ pagerView: FSPagerView, didSelectItemAt index: Int) {
        pagerView.deselectItem(at: index, animated: true)
        pagerView.scrollToItem(at: index, animated: true)
    }
    
    func pagerViewWillEndDragging(_ pagerView: FSPagerView, targetIndex: Int) {
//        self.pageControl?.currentPage = targetIndex
        self.bannerNumberLabel?.text = String(format: "%d/%d", targetIndex+1,self.goodsDetailModel?.goodsBannerSlideImgUrl?.count ?? 0)
    }
    
    func pagerViewDidEndScrollAnimation(_ pagerView: FSPagerView) {
//        self.pageControl?.currentPage = pagerView.currentIndex
        self.bannerNumberLabel?.text = String(format: "%d/%d", pagerView.currentIndex+1,self.goodsDetailModel?.goodsBannerSlideImgUrl?.count ?? 0)
    }
}
